package util

import (
	"github.com/golang-jwt/jwt/v4"
	"github.com/zachary/tbox/internal/types"
	"time"
)

// GetJwtToken
// @secretKey: JWT 加解密密钥
// @seconds: 过期时间，单位秒
// @token: 数据载体
func GetJwtToken(secretKey string, seconds int64, token *types.TokenClaims) (string, error) {
	token.RegisteredClaims = jwt.RegisteredClaims{
		ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Second * time.Duration(seconds))),
		Issuer:    "zachary",
		IssuedAt:  jwt.NewNumericDate(time.Now()),
		NotBefore: jwt.NewNumericDate(time.Now()),
	}
	claims := jwt.NewWithClaims(jwt.SigningMethodHS256, token)
	mySigningKey := []byte(secretKey)
	signedString, err := claims.SignedString(mySigningKey)
	return signedString, err
}
